﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for SiteAdmin
/// </summary>
public class SiteAdminBase : BasePage
{
    public SiteAdminBase()
    {
        this.Theme = "DefaultSkin";
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!ConfigManager.Debug && string.IsNullOrEmpty(SessionManager.LoginName))
        {
            Response.Redirect("~/SiteAdmin/DefaultLogin.aspx");
        }
        if (Page.Title == null || Page.Title == "Untitled Page")
        {
            Page.Title = "Openfree - " + ConfigManager.SiteSubject;
        }
        
        ReInitHeader();

        string state = SessionManager.Username;
        if (!string.IsNullOrEmpty(SessionManager.UserRole))
        {
            state += "[" + SessionManager.UserRole + "]";
        }
        Page.ClientScript.RegisterStartupScript(this.GetType(), string.Empty,
            JavaScript.InBox("window.status = '" + state + "'"));
    }

    protected virtual void ReInitHeader()
    {
        int count = Page.Header.Controls.Count - 1;
        for (int i = count; i >= 0; i--)
        {
            HtmlControl c = Page.Header.Controls[i] as HtmlControl;
            if (c != null && c.Attributes["type"] != null &&
                c.Attributes["type"].Equals("text/css", StringComparison.OrdinalIgnoreCase))
            {
                Page.Header.Controls.Remove(c);
            }
        }
        string link = "    <link href=\"../App_Themes/" + Page.Theme +
            "/{0}\" type=\"text/css\" rel=\"stylesheet\" />\r\n";
        Literal lit = new Literal();
        lit.Text = string.Format(link, "00.share.css") +
            string.Format(link, "10.menu.css") +
            string.Format(link, "11.manager.css") +
            string.Format(link, "11.tabsMenu.css") +
            string.Format(link, "01.gridView.css") + "    ";
        Page.Header.Controls.Add(lit);
    }
}
